import { Application } from "kilom/lib/Application";

/**
 * 创建单例
 * ```
 * static get ins(){ singleton(this);}
 * ```
 */
export function singleton<T extends new (...args: any[]) => any>(cls: T, field = "ins"): InstanceType<T> {
    return Object.defineProperty(cls, field, { value: new cls() })[field];
}

/**
 * 代码文件后缀
 * @returns 
 */
export function getFormat(app: Application) {
    return app.isTs ? ".ts" : ".js";
}